<?php

namespace App\Http\Controllers\System;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use JPush\Client;

class PushController extends Controller
{
    private $app_key        = '3b9ed41737554ff5ec479710';
    private $master_secret  = '06a1f1cf1a771274d9230d6b';
    public  $client;
    public function __construct()
    {
        $client         = new Client($this->app_key, $this->master_secret);
        $this->client   = $client;
    }

    public function testPush(Request $request)
    {
        $content = $request->input('content');
        $res= $this->client->push()
            ->setPlatform('all')
            ->addAllAudience()
            ->iosNotification($content, [
                'sound' => 'default',
                'badge' => '+1',
                'content-available'=>true,
                'mutable-content' => true,
                'extras' => [
                    'img' => 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535104472362&di=420ceb6a65f2462cad94cd9a7c983684&imgtype=0&src=http%3A%2F%2Fwww.qqma.com%2Fimgpic2%2Fcpimagenew%2F2018%2F4%2F5%2F6e1de60ce43d4bf4b9671d7661024e7a.jpg'
                ]
            ])
            ->send();
        dd($res['http_code']);
    }

    public function Push(string $content,array $extras)
    {
        $res= $this->client->push()
            ->setPlatform('all')
            ->addAllAudience()
            ->iosNotification($content, [
                'sound' => 'default',
                'badge' => '+1',
                'content-available'=>true,
                'mutable-content' => true,
                'extras' =>$extras
            ])
            ->send();
    }

    public function PushToAliasBuyUid(string $uid,string $content,array $extras=[])
    {
        $this->client->push()
            ->setPlatform('all')
            ->addAlias($uid)
            ->iosNotification($content, [
                'sound' => 'default',
                'badge' => '+1',
                'content-available'=>true,
                'mutable-content' => true,
                'extras' =>$extras
                ])
            ->send();
    }


}
